#ifndef __LOCK_GUARD_H_
#define __LOCK_GUARD_H_

#include <iostream>
#include <pthread.h>

using namespace std;

class Mutex
{
public:
    Mutex(pthread_mutex_t* mtx)
        :mtx_(mtx)
    {}

    void lock()
    {
        pthread_mutex_lock(mtx_);
    }

    void unlock()
    {
        pthread_mutex_unlock(mtx_);
    }

private:
    pthread_mutex_t* mtx_;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mtx)
        :mutex(mtx)
    {
        cout<<"lock begin"<<endl;
        mutex.lock();
    }

    ~LockGuard()
    {
        cout<<"unlock end"<<endl;
        mutex.unlock();
    }


private:
    Mutex mutex;
};
#endif